package com.rayo.accesscontrollercopy.model.db.dao;

import com.litesuits.orm.db.assit.QueryBuilder;
import com.rayo.accesscontrollercopy.model.db.DbHelp;
import com.rayo.accesscontrollercopy.model.db.bean.CardTimezoneData;

import java.util.List;


/**
 * Created by yanghaojie on 16/7/27.
 */
public class CardTimeImpl implements CardTimeDao {
    @Override
    public List<CardTimezoneData> findAll() {
        return DbHelp.getQueryAll(CardTimezoneData.class);
    }

    @Override
    public CardTimezoneData findByNo(int no, int serial) {

        QueryBuilder qb = new QueryBuilder(CardTimezoneData.class).whereEquals(CardTimezoneData.USERID, no)
                .whereAppendAnd().whereEquals(CardTimezoneData.SERIAL_ID, serial);
        List<CardTimezoneData> cardTimezoneDatas = DbHelp.liteOrm.query(qb);
        if (null == cardTimezoneDatas || cardTimezoneDatas.size() == 0) return null;
        else return cardTimezoneDatas.get(0);
    }

    @Override
    public List<CardTimezoneData> findByUserId(int userId) {
        QueryBuilder qb = new QueryBuilder(CardTimezoneData.class).whereEquals(CardTimezoneData.USERID, userId);
        List<CardTimezoneData> cardTimezoneDatas = DbHelp.liteOrm.query(qb);
        return cardTimezoneDatas;
    }

    @Override
    public void addAll(List<CardTimezoneData> cardTime) {
        DbHelp.insertAll(cardTime);
    }

    @Override
    public void addCardTime(CardTimezoneData cardTime) {
        DbHelp.insert(cardTime);
    }

    @Override
    public void updateAll(List<CardTimezoneData> cardTime) {
        DbHelp.updateALL(cardTime);
    }

    @Override
    public void updateCardTime(CardTimezoneData cardTime) {
        DbHelp.update(cardTime);
    }

    @Override
    public void deleteAll() {
        DbHelp.deleteAll(CardTimezoneData.class);
    }

    @Override
    public void deleteByNo(int no) {
        DbHelp.deleteWhere(CardTimezoneData.class, CardTimezoneData.USERID,
                new String[]{String.valueOf(no)});
    }
}
